#pragma once
/*! \file
 * IIntrReplayEx.h
 *
 */

#include "../_inc/def_interface.h"
/*!
 * \brief Interface class for searching files and playback video and audio
 *
 * This is an interface class for searching file and playback
 *
 * - header file: IIntrReplayEx.h
 * - lib: search.lib
 * - DLL: search.dll
 */
class AFX_EXT_CLASS IIntrReplayEx
{
public:
	/*!
	 * Creates search and playback manager object
	 *
	 * @return Search and playback manager object. If NULL, failed to get the object.
	 */
	static IIntrReplayEx *Create();
	virtual ~IIntrReplayEx(void); /**< Destructor 	*/

protected:
	IIntrReplayEx(void);

	CALLBACK_APP	m_pCallbackProc;
	LPVOID			m_pCallbackParam;

	int m_nRecMode;
	ST_AVI_NAME_FORMAT m_stAviNameFormat;
	ST_FILE_NAME_FORMAT m_stFileNameFormat;

	TCHAR m_tzLogPath[MAX_PATH];
	TCHAR m_tzDbPath[MAX_PATH];

	int m_nSearchType;
	BOOL m_bRecovery;

public:
	/*!
	 * Creates search objects and a playback object.
	 * And initialize the objects.
	 *
	 * @param pWnd Pointer to the parent window
	 * @param nParam must set to 2
	 *
	 * @return Returns TRUE if it is successful.
	 */
	virtual BOOL Initialize(CWnd *pWnd, int nParam) { return FALSE; };
	/*!
	 * Release all objects and resources.
	 */
	virtual void Release() {};
	/*!
	 * Sets callback function
	 *
	 * @param pCallbackProc Specifies the address of the PCALLBACK_APP callback function.
	 * @param pCallbackParam Pointer to the context that will be supplied when callback function is called.
	 *
	 * @remark
	 * This object delivers services.
	 * The services are define at enum _Bak
	 * and services are the followings:
	 *
	 *	LIST_RESET : resets recording information list
	 *	LIST_INSERT : inserts individual information to the recording information list
	 *	LIST_SORT : sorts individual information to the recording information list
	 *	TIMELIST_LOAD : load the list to the time list
	 *	EVENTLIST_LOAD : load the list to the event list
	 *	
	 *	TIMELIST_GET_INDEX : gets index information from time list
	 *	TIMELIST_GET_INDEX_NO : gets index number from time list
	 *	TIMELIST_GET_SELECT_INDEX_NO : get index number from time list, especially selected
	 *	
	 *	EVENTLIST_GET_INDEX : gets index information from event list
	 *	EVENTLIST_GET_INDEX_NO : gets index number from event list
	 *	EVENTLIST_GET_SELECT_INDEX_NO : get index number from event list, especially selected
	 *	
	 *	TIMELIST_GET_CHECK_INDEX_START : gets the first selected index number from time list
	 *	TIMELIST_GET_CHECK_INDEX_NEXT : gets the next selected index number from time list.
	 *
	 *	EVENTLIST_GET_CHECK_INDEX_START : gets the first selected index number from event list
	 *	EVENTLIST_GET_CHECK_INDEX_NEXT : gets the next selected index number from event list.
	 *	
	 *	SEND_USER_INFO : during the play, send information about GPS, G-Sensor etc to the application
	 *	SEND_USER_DATA : during the play, send user data to the application
	 *	SEND_IMAGE : during the play, send the current video data to the application
	 *	SEND_AUDIO : during the play, send the current audio data to the application
	 *	
	 *	POPUP_STREAM : send video data selected for a pop-up screen or full screen purposes
	 *	POPUP_STREAM_LOGO : inform to the application to draw logo image to the pop-up screen or full screen.
	 *	
	 *	REPMGR_STOP : Stopped by inside process
	 *	GSENSOR_CLEAR : send command to clear g-sensor data(graph)
	 *	MAP_STOP : send command to stop working map
	 *	TIMEBAR_LOAD : send information about the number of I-frames int the current file
	 *
	 * @see _Cmd
	 */
	virtual void SetCallback(PCALLBACK_APP pCallbackProc, LPVOID pCallbackParam);

	/*!
	 * Sets log file path
	 *
	 * @param tzLogPath Full path of log file to be saved.
	 */
	virtual void SetLogPath(TCHAR *tzLogPath) { wsprintf(m_tzLogPath, _T("%s"), tzLogPath); };
	/*!
	 * Sets AVI file name parsing format
	 * When parses AVI file name, it follows the rule or structure of ST_AVI_NAME_FORMAT
	 * 
	 * File name can be different from each customer.
	 * This supports that each customer has their own file name format
	 *
	 * @param stAviNameFormat
	 */
	virtual void SetAviFileNameFormat(ST_AVI_NAME_FORMAT stAviNameFormat) { m_stAviNameFormat = stAviNameFormat; };
	/*!
	 * Sets AVS file name parsing format
	 * It does not have much information about file name
	 * 
	 * @param stFileNameFormat
	 */
	virtual void SetAviFileNameFormat(ST_FILE_NAME_FORMAT stFileNameFormat) { m_stFileNameFormat = stFileNameFormat; };
	/*!
	 * Supports some options of using user data
	 *
	 * @param bUserFormat customer can use their own user data format when bUserFormat is TRUE.
	 * if bUserFormat is FALSE, user data is applied by default.
	 * 
	 * @param dwUserFormatSize Size of user data
	 * @param bReadInAdvance if TRUE, reads user data in advance when opens a file.
	 */
	virtual void SetUserFormatStatus(BOOL bUserFormat, DWORD dwUserFormatSize, BOOL bReadInAdvance) {};
	/*!
	 * When you use AV2 file format, user should define audio format.
	 *
	 * @param nAudioFormat Waveform format Linear PCM = 1, MULAW PCM = 7
	 * @param nAudioFrequecy Waveform frequency in Hz
	 * @param nAudioBitPerSample Waveform bits per samples of which values are 8 or 16 only.
	 */
	virtual void SetAudioFormat(int nAudioFormat, int nAudioFrequecy, int nAudioBitPerSample) {};

	/*!
	 * Sets image brightness
	 *
	 * @param nChannel channel number
	 * @param nValue the value of brightness which ranged between 0 to 100
	 */
	virtual void SetBrightness(int nChannel, int nValue) {};
	/*!
	 * Sets image contrast
	 *
	 * @param nChannel channel number
	 * @param nValue the value of contrast which ranged between 0 to 100
	 */
	virtual void SetContrast(int nChannel, int nValue) {};
	/*!
	 * Sets image saturation
	 *
	 * @param nChannel channel number
	 * @param nValue the value of saturation which ranged between 0 to 100
	 */
	virtual void SetSaturation(int nChannel, int nValue) {};

	virtual void SetSharpeness(int nChannel, int nValue) {};
	virtual void SetBlur(int nChannel, int nValue) {};

	/*!
	 * Sets directory where the recorded files exist
	 *
	 * @param tzDbPath directory path
	 */
	virtual void SetDbPath(TCHAR *tzDbPath) { wsprintf(m_tzDbPath, _T("%s"), tzDbPath); };
	/*!
	 * Checks whether recorded files exist or are available.
	 *
	 * @return returns TRUE if files are available to play. FALSE otherwise.
	 */
	virtual BOOL CheckRecordMode() { return FALSE; };
	/*!
	 * Returns what type the files recorded.
	 * 
	 * @return type of record files
	 *
	 *	RECMODE_UNKNOWN : no file or unsupported file format
	 *	RECMODE_AV2 : Recording files are AV2 format
	 *	RECMODE_AVI : Recording files are AVI format
	 *
	 * @see _tagRECMODE
	 */
	virtual int GetRecordMode() { return m_nRecMode; }; 

	/*!
	 * There are 2 type of search mode
	 * One is to search from the time list and the other is to search from the event list
	 * This function sets search mode
	 *
	 * @param nSearchType
	 *
	 *	search_time : search from the time list
	 *	search_event : search from the event list
	 *
	 * @see SEARCH_TYPE
	 */
	virtual void SetSearchType(int nSearchType)	{ m_nSearchType = nSearchType; };
	/*!
	 * Gets search mode
	 * 
	 * @return Search mode
	 * @see SEARCH_TYPE
	 */
	virtual int GetSearchType() { return m_nSearchType; };

	/*!
	 * Sets playback speed
	 * 
	 * @param nPBSpeed playback speed
	 *
	 *	0 : x1/4 speed(slow)
	 *	1 : x1/2 speed(slow)
	 *	2 : normal speed
	 *	3 : x2 speed(fast)
	 *	4 : x4 speed(fast)
	 *
	 */
	virtual void SetPBSpeed(int nPBSpeed) {};

	virtual BOOL PlayForward() { return FALSE; };	//!< Playback command of forward-play
	virtual BOOL PlayBackward() { return FALSE; };	//!< Playback command of backward-play
	virtual BOOL Pause() { return FALSE; };		//!< Playback command of pause
	virtual BOOL Stop() { return FALSE; };		//!< Playback command of stop
	/*!
	 * Playback command of moving 1 frame forward
	 *
	 * @param nList if nList<0, it moves current file opened. if nList = 0, it moves the following file
	 */
	virtual BOOL StepForward(int nList = -1) { return FALSE; }; 
	/*!
	 * Playback command of moving 1 key frame forward
	 *
	 * @param nList if nList<0, it moves current file opened. if nList = 0, it moves the following file
	 */
	virtual BOOL StepForwardKeyframe(int nList = -1) { return FALSE; }; 
	/*!
	 * Playback command of moving 1 frame backward : this function does not support
	 *
	 * @param nList if nList<0, it moves current file opened. if nList = 0, it moves the previous file
	 */
	virtual BOOL StepBackward(int nList = -1) { return FALSE; };

	/*!
	 * Playback command of moving 1 key frame backward
	 *
	 * @param nList if nList<0, it moves current file opened. if nList = 0, it moves the previous file
	 */
	virtual BOOL StepBackwardKeyframe(int nList = -1) { return FALSE; };

	/*!
	 * After stops, you must call this function to release video and audio data in the internal queues.
	 */
	virtual void ClearData() {};

	/*!
	 * Playing starts a certain file with direction 
	 *
	 * @param nIndex index in the list 
	 * @param bDirection if TRUE, plays forward. Otherwise plays backward
	 * 
	 * @return Returns TRUE, it plays successfully.
	 */
	virtual BOOL PlayList(int nIndex, BOOL bDirection = TRUE) { return FALSE; };
	/*!
	 * Gets play status
	 *
	 * @return Returns play status
	 *
	 *	pst_stopped : stop
	 *	pst_playforward : play forward
	 *	pst_playbackward : play backward
	 *	pst_pause : pause
	 *
	 * @see PLAYER_STATE
	 */
	virtual int GetPlayerState() { return pst_stopped; };

	/*!
	 * Display the current image to the display window
	 */
	virtual void ShowCurrentImage() {};
	/*!
	 * Selects a full screen channel
	 *
	 * @param nPopupChannel a channel to be shown in the full screen or pop-up screen
	 */
	virtual void PopupRequest(int nPopupChannel) {};
	virtual void InitPopupScreen() {};	//not used
	virtual void ClosePopup() {};		//not used

	/*!
	 * Pause play temporally
	 */
	virtual BOOL HoldCurrentImage() { return FALSE; };
	/*!
	 * Play the previous action before calling HoldCurrentImage
	 */
	virtual BOOL ReleaseCurrentImage() { return FALSE; };
	/*!
	 * Moves directly to the position with the given position and
	 * shows an image
	 *
	 * @param nIFrameIndexPos the position of I-frame
	 */
	virtual BOOL GotoTimeSearch(int nIFrameIndexPos) { return FALSE; };
	/*!
	 * The same functionality of GotoTimeSearch
	 */
	virtual BOOL GotoTimeSearchBegin(int nIFrameIndexPos) { return FALSE; };

	/*!
	 * Get pointer to the latest image to be shown
	 * 
	 * @param nChannel channel number
	 * @param nWidth Pointer to the integer value that contains image width
	 * @param nHeight Pointer to the integer value that contains image height
	 * @param nOutputFormat Pointer to the value that contains image format
	 *
	 *	FMT_YUV422PK_UD : YUV422 packed image and upside down
	 *	FMT_YUV422PL_UU : YUV422 planar image
	 *	FMT_RGB : RGB 32bit image
	 *
	 * @return Returns pointer to the buffer which contains image data. If NULL there is no video data
	 *
	 * @see _TAG_VIDEO_FORMAT
	 */
	virtual BYTE *GetLastVideoImage(int nChannel, int *nWidth, int *nHeight, int *nOutputFormat) { return NULL; };

	/*!
	 * Gets the current index number
	 *
	 * @param nChannel channel number
	 *
	 * @return Returns the current index number 
	 */
	virtual int GetCurrentIndex(int nChannel) { return -1; };
	virtual void SetAudioDelay(int nDelay) {};

	/*!
	 * Delete recorded files
	 *
	 * @param nSearchType search type
	 *
	 * @return Returns -1 when it fails. Otherwise it deletes files successfully.
	 *
	 * @remark
	 * This function deletes files which selected in the list 
	 *
	 */
	virtual int DeleteSelectedFile(SEARCH_TYPE nSearchType) { return -1; };
	/*!
	 * Set playback options associated with speed
	 *
	 * @param nPBSpeedOption an option, see the followings:
	 *
	 *	PB_SPEED_OPT_ALL_FRAMES : plays all frames
	 *	PB_SPEED_OPT_I_FRAME_X4 : plays I-frames only when playback speed is x4(4-time faster)
	 *	PB_SPEED_OPT_I_FRAME_X2 : plays I-frames only when playback speed is more than x2(2-time faster)
	 *
	 * @see _PB_SPEED_OPTION
	 *
	 */
	virtual void SetPBSpeedOption(int nPBSpeedOption) {};

	/*!
	 * Gets the number of total recorded files that represents channel 0
	 */
	virtual int TotalStreamFileCount() { return 0; };
	/*!
	 * Open lists
	 *
	 * @return Returns TRUE if it scans files successfully. FALSE otherwise.
	 */
	virtual BOOL procOpenList() { return FALSE; };
	/*!
	 * Set callback function to show the progress status while scanning files
	 *
	 * @param pCallbackProc Specifies the address of the PCALLBACK_APP callback function.
	 * @param pCallbackParam Pointer to the context that will be supplied when callback function is called.
	 *
	 * @remark
	 * Callback service command supports the following:
	 *
	 *	FILE_OPEN_PROGRESS_INC
	 *
	 * @see _Cmd
	 */
	virtual void SetProgressCallback(PCALLBACK_APP pCallbackProc, LPVOID pCallbackParam) {};

	/*!
	 * set to the delay time of the rear camera
	 *
	 * @param nDelay delay time in milliseconds which ranges -1500 to 1500
	 */
	virtual void SetRearCameraDelay(int nDelay) {};

	/*!
	 * enable or disable AVI file recovery function
	 *
	 * @param bEnable if TRUE, Recovery function is enabled, otherwise disabled
	 */
	virtual void EnableRecovery(BOOL bEnable) { m_bRecovery = bEnable; };


};
